package com.hncc.dms.controller;

import java.util.List;

import com.hncc.dms.domain.DmsDrug;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hncc.dms.service.IDmsDrugService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;

/**
 * 药品管理Controller
 * 
 * @author ruoyi
 * @date 2020-08-13
 */
@RestController
@RequestMapping("/dms/drug")
@Api(tags = "药品管理接口")
public class DmsDrugController extends BaseController
{
    @Resource
    private IDmsDrugService dmsDrugService;

    /**
     * 查询药品管理列表
     */
    @ApiOperation(value = "条件分页查询药品管理",httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('dms:drug:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsDrug dmsDrug)
    {
        startPage();
        List<DmsDrug> list = dmsDrugService.selectDmsDrugList(dmsDrug);
        return getDataTable(list);
    }

    /**
     * 导出药品管理列表
     */
    @PreAuthorize("@ss.hasPermi('dms:drug:export')")
    @Log(title = "药品管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DmsDrug dmsDrug)
    {
        List<DmsDrug> list = dmsDrugService.selectDmsDrugList(dmsDrug);
        ExcelUtil<DmsDrug> util = new ExcelUtil<DmsDrug>(DmsDrug.class);
        return util.exportExcel(list, "drug");
    }

    /**
     * 获取药品管理详细信息
     */
    @ApiOperation(value = "根据id获取药品管理详细信息",httpMethod = "GET",
            notes = "根据id查询药品管理")
    @ApiImplicitParam(paramType = "path",name = "id",value = "药品管理id",dataType = "Long",required = true)
    @PreAuthorize("@ss.hasPermi('dms:drug:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dmsDrugService.selectDmsDrugById(id));
    }

    /**
     * 新增药品管理
     */
    @ApiOperation(value = "新增",httpMethod = "POST", notes = "新增药品管理")
    @ApiImplicitParam(name = "dmsDrug", value = "新增药品管理", dataType = "DmsDrug")
    @PreAuthorize("@ss.hasPermi('dms:drug:add')")
    @Log(title = "药品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsDrug dmsDrug)
    {
        return toAjax(dmsDrugService.insertDmsDrug(dmsDrug));
    }

    /**
     * 修改药品管理
     */
    @ApiOperation(value = "修改", httpMethod = "PUT", notes = "修改药品管理")
    @ApiImplicitParam(name = "dmsDrug", value = "修改药品管理", dataType = "DmsDrug")
    @PreAuthorize("@ss.hasPermi('dms:drug:edit')")
    @Log(title = "药品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsDrug dmsDrug)
    {
        return toAjax(dmsDrugService.updateDmsDrug(dmsDrug));
    }

    /**
     * 删除药品管理
     */
    @ApiOperation(value = "批量删除", httpMethod = "DELETE", notes = "根据ids删除药品管理")
    @ApiImplicitParam(paramType = "path",name = "ids",value = "药品管理id",dataType = "Long[]",required = true)
    @PreAuthorize("@ss.hasPermi('dms:drug:remove')")
    @Log(title = "药品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsDrugService.deleteDmsDrugByIds(ids));
    }

    /**
     * 获取包装单位集合
     * @return
     */
    @ApiOperation(value = "获取包装单位", httpMethod = "GET", notes = "获取所有包装单位")
    @GetMapping("/getUnitList")
    public AjaxResult getUnitList(){
        return AjaxResult.success(dmsDrugService.selectUnitList());
    }

//    /**
//     * 获取所属人的成药，草药集合
//     * @param smsFrequentUsed
//     * @return
//     */
//    @GetMapping("/getFrequentUsedDrug")
//    public TableDataInfo getFrequentUsedDrug(SmsFrequentUsed smsFrequentUsed){
//        System.out.println("usedToString->>>"+smsFrequentUsed.getDrugIdList());
//        startPage();
//        List<DmsDrug> list = dmsDrugService.selectDmsDrugByTypeIdOrId(smsFrequentUsed.getType(),smsFrequentUsed.getDrugIdList().split(","));
//        return getDataTable(list);
//    }
}
